package com.whately.core.base.controller;

import com.google.common.collect.Maps;
import com.whately.core.base.annotation.IgnoreAccessKey;
import com.whately.core.base.annotation.IgnoreSession;
import com.whately.core.base.model.ApiResponse;
import com.whately.core.base.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api")
@Slf4j
public class WhatelyClientSignController {

    /**
     * ak  每个前端项目-分配不同的access key
     *
     * ak 把参数加密，生成sign_key
     *
     */
    @PostMapping(params = "method=whately.core.client.sec.accesskey")
    @IgnoreSession
    @IgnoreAccessKey
    public ApiResponse<Map<String,String>> fetchAccessKey() {
        //32位uuid+时间戳
        String timestamp = ""+DateUtil.nowSecond();
        String accessKey= ClientSignUtil.geneAkSimple(timestamp);

        Map<String,String> map= Maps.newHashMap();
        map.put("accessKey",accessKey);
        map.put("accessTimestamp",timestamp);

        return ApiResponse.<Map<String,String>>builder().data(map).build();
    }

}
